/* Copyright (c) 2024 Huawei Technologies Co., Ltd.
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 * ===================================================================================================================*/

#include "exe_graph/lowering/value_holder_utils.h"

namespace gert {
namespace bg {
bool ValueHolderUtils::IsNodeValid(const ValueHolderPtr &holder) {
  if (holder == nullptr) {
    return false;
  }
  return (holder->fast_node_ != nullptr);
}

bool ValueHolderUtils::IsNodeEqual(const ValueHolderPtr &src, const ValueHolderPtr &dst) {
  if (src == dst) {
    return true;
  }
  if ((src == nullptr) || (dst == nullptr)) {
    return false;
  }
  return (src->fast_node_ == dst->fast_node_);
}

std::string ValueHolderUtils::GetNodeName(const ValueHolderPtr &holder) {
  if (holder == nullptr) {
    return "";
  }
  return holder->op_desc_->GetName();
}
const char *ValueHolderUtils::GetNodeNameBarePtr(const ValueHolderPtr &holder) {
  if (holder == nullptr) {
    return "";
  }
  return holder->op_desc_->GetNamePtr();
}
std::string ValueHolderUtils::GetNodeType(const ValueHolderPtr &holder) {
  if (holder == nullptr) {
    return "";
  }
  return holder->op_desc_->GetType();
}
const char *ValueHolderUtils::GetNodeTypeBarePtr(const ValueHolderPtr &holder) {
  if (holder == nullptr) {
    return "";
  }
  return holder->op_desc_->GetTypePtr();
}

ge::OpDescPtr ValueHolderUtils::GetNodeOpDesc(const ValueHolderPtr &holder) {
  if (holder == nullptr) {
    return nullptr;
  }
  return holder->op_desc_;
}
ge::OpDesc *ValueHolderUtils::GetNodeOpDescBarePtr(const ValueHolderPtr &holder) {
  if (holder == nullptr) {
    return nullptr;
  }
  return holder->op_desc_.get();
}

bool ValueHolderUtils::IsDirectlyControlled(const bg::ValueHolderPtr &src, const bg::ValueHolderPtr &dst) {
  if (src == nullptr || dst == nullptr) {
    return false;
  }
  return dst->fast_node_->IsDirectlyControlledByNode(src->fast_node_);
}
} // bg
} // gert
